#include "Avatar.h"

const HashedString Avatar::resourceType("Avatar");

bool Avatar::ToXML( tinyxml2::XMLPrinter& printer )
{
}

bool Avatar::FromXML( tinyxml2::XMLElement* element )
{
	for (tinyxml2::XMLElement* attribute = element->FirstChildElement("Attribute"); attribute != NULL; attribute = attribute->NextSibling())
	{
		HashedString type(attribute->Attribute("Type"));
		Attribute& attri = m_attributes[type];
		
		if (type == HashedString("EntityController"))
		{
			HashedString behavior(attribute->Attribute("Behavior"));
			attri.attributes["Behavior"] = behavior;
		} else if (type == HashedString("OrientationComponent"))
		{
		} else if (type == HashedString("GraphicalComponent"))
		{
			HashedString model(attribute->Attribute("ModelName"));
			attri.attributes["ModelName"] = model;
		} else if (type == HashedString("RigidBodyComponent"))
		{
			for (tinyxml2::XMLElement* shape = attribute->FirstChildElement("Shape"); shape != NULL; shape = shape->NextSiblingElement())
			{
				HashedString shapeType(shape->Attribute("Type"));
				attri.attributes[shapeType];
				if (shape->Attribute("Radius"))
					attri.attributes[shapeType] = HashedString(shape->Attribute("Radius"));
			}
		} else if (type == HashedString("SelectableComponent"))
		{
			for (tinyxml2::XMLElement* shape = attribute->FirstChildElement("Shape"); shape != NULL; shape = shape->NextSiblingElement())
			{
				HashedString shapeType(shape->Attribute("Type"));
				attri.attributes[shapeType];
				if (shape->Attribute("Radius"))
					attri.attributes[shapeType] = HashedString(shape->Attribute("Radius"));
			}
		} else if (type == HashedString("StatusComponent"))
		{
			for (tinyxml2::XMLElement* stat = attribute->FirstChildElement("Status"); stat != NULL; stat = stat->NextSiblingElement())
			{
				HashedString statusName(stat->Attribute("Name"));
				attri.attributes[statusName];
				if (stat->Attribute("Value"))
					attri.attributes[statusName] = HashedString(stat->Attribute("Value"));
			}
		} else if (type == HashedString("CombatComponent"))
		{
			for (tinyxml2::XMLElement* effect = attribute->FirstChildElement("Effect"); effect != NULL; effect = effect->NextSiblingElement())
			{
				HashedString effectName(effect->Attribute("Name"));
				attri.attributes[effectName];
			}
			for (tinyxml2::XMLElement* ability = attribute->FirstChildElement("Ability"); ability != NULL; ability = ability->NextSiblingElement())
			{
				HashedString abilityName(ability->Attribute("Name"));
				attri.attributes[abilityName];
			}
		}
	}
}

const HashedString& Avatar::getResourceType() const
{
	return resourceType;
}

Avatar::Attribute::Map_t& Avatar::Attributes()
{
	return m_attributes;
}